<?php
get_header(); 
function closetags ( $html )
{
    #put all opened tags into an array
    preg_match_all ( "#<([a-z]+)( .*)?(?!/)>#iU", $html, $result );
    $openedtags = $result[1];
    #put all closed tags into an array
    preg_match_all ( "#</([a-z]+)>#iU", $html, $result );
    $closedtags = $result[1];
    $len_opened = count ( $openedtags );
    # all tags are closed
    if( count ( $closedtags ) == $len_opened )
    {
    return $html;
    }
    $openedtags = array_reverse ( $openedtags );
    # close tags
    for( $i = 0; $i < $len_opened; $i++ )
    {
        if ( !in_array ( $openedtags[$i], $closedtags ) )
        {
        $html .= "</" . $openedtags[$i] . ">";
        }
        else
        {
        unset ( $closedtags[array_search ( $openedtags[$i], $closedtags)] );
        }
    }
    return $html;
}
$option = get_option('kkfashion_1_settings');
 ?>
<style type="text/css">
    #carousel-example-captions{
        margin: 0;
    }
    .thumb-product.thumb-news {
    margin-top: -200px;
    }
    .header.product.news {
    height: 330px;
    }
    .product .header-description .title .line_1{
        margin-left: 0;
    }
@media (max-width: 767px){
    .thumb-product.thumb-news{
        margin-top: -90px;
    }
}
</style>
 <script type="text/javascript">
    $('.header').addClass('product news hnews');
</script>
<script src="<?php echo bloginfo('template_url'); ?>/js/jquery-migrate-1.2.1.js"></script>
            <div class="row">
                <div class="col-lg-5 col-sm-6 col-12"></div>
                <div class="col-lg-7 col-sm-6 col-12 header-description">
                    <?php
                    wp_reset_query();
                    if (have_posts())
                    while (have_posts()) : the_post();
                        ?>
                        <div class="title step">
                        <div class="line_1"><h2><?php the_title(); ?></h2></div> 
                      
                    </div>
                    <p class="mt20s">
                        <?php if( strpos(get_the_content(), '<span id="more-') ) : ?>
                          <?php global $more; $more=0; echo get_the_content(''); $more=1; ?>
                        <?php endif; ?>   
                    </p>
                    <?php endwhile; ?>
                </div>
            </div>
        </div>
    </div>
   
    <!-- Content -->
    <div class="main-content container su_kien_2">
        <div class="row">
            <?php
                wp_reset_query();
                if (have_posts())
                while (have_posts()) : the_post();
                if (has_post_thumbnail()) {
                   $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                   $url_to_image = $large_image_url[0];
                } else {
                 $url_to_image = bloginfo('template_url').'/img/no-image-blog-one.png';
                }
                $abs_image = str_replace('http://'.$_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $url_to_image);
                if(!file_exists($abs_image)) $url_to_image = str_replace('E12', 'E 12', $url_to_image );
                $abs_image = str_replace('http://'.$_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $url_to_image);
                if(!file_exists($abs_image)) $url_to_image = site_url().'/wp-content/uploads/no_image.jpg';
                ?>
                <div class="col-lg-5 col-sm-6 col-12 thumb-product thumb-news">
                    <img src="<?php echo $url_to_image ?>" class="img-thumbnail">
                  </div>
                <div class="col-lg-7 col-sm-6 col-12 m30 pull-right">
                    <div>
                    Tag: <?php 
                    foreach(explode(",", $option['news_tags']) as $tag ){
                        $tagurl = get_site_url().'/product-tag/'.str_replace(' ','-',trim(vn_str_filter($tag)));
                        echo "<a href='$tagurl'>$tag</a>, "; 
                    }
                    ?>
                    </div>
                     <!-- AddThis Button BEGIN -->
                    <div class="addthis_toolbox addthis_default_style " style="display:none;">
                    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                    <a class="addthis_button_tweet"></a>
                    <a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
                    <a class="addthis_counter addthis_pill_style"></a>
                    </div>
                    <script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>
                    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-50b9773b081d0217"></script>
                    <!-- AddThis Button END -->
                </div>
                <?php endwhile; ?>
        </div>
        <div class="row">
            <div class="col-lg-8">
                <?php
                    wp_reset_query();
                    if (have_posts())
                    while (have_posts()) : the_post(); ?>
                    <?php echo closetags(get_the_content('', true)); ?> 
                <?php endwhile; ?>
                <script type="text/javascript">
                $('.su_kien_2 .col-lg-8 img').addClass('img-thumbnail').each(function(){
                    $('<div class="img-shadow"></div>').insertBefore($(this));
                    $(this).prev().html($(this));
                });
                </script>
                <div class="contact-page no-left">
                    <p class="contact-name no-uppercase">Các tin tức khác</p>
                    <ul class="news-list">
                    <?php global $post;
                    $currCat = get_the_category($post->ID);
                    $currPost = $post->ID;
                    ?>
                    <?php
                        wp_reset_query();
                        query_posts(array('order'=>'ASC','category__in' => array($currCat[0]->cat_ID),'posts_per_page'=>6,'offset'=>0));
                        while (have_posts()): the_post(); ?>
                        <?php if($currPost==get_the_ID()) continue; ?>
                        <li ><a href="<?php the_permalink() ?>"><?php the_title(); ?> (<?php the_time('d.m.Y') ?>)</a></li>
                        <?php endwhile; ?>
                    </ul>
                </div>
                <div class="clearfix"></div>
            </div>
            <?php get_sidebar('product') ?>               

        </div>
    </div>
    <!-- End Content -->
<script type="text/javascript">
    $('.hnews .header-description p:contains("Tags")').remove();
    </script>
<link href="<?php echo bloginfo('template_url'); ?>/css/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
<script src="<?php echo bloginfo('template_url'); ?>/js/jquery.mCustomScrollbar.min.js"></script>
<?php get_footer() ?>
